//
//  WUMineViewController.m
//  Home
//
//  Created by 吴军虎吴军虎 on 16/4/29.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "WUMineViewController.h"
#import "WUMineCell.h"
#import "WUMineHeaderView.h"
#import "WUMineFooterView.h"
#import "SheeViewController.h"
#import "WUVippViewController.h"
#import "VipViewController.h"
#import "SupViewController.h"
#import "YHYDesignerPersonViewController.h"//我的主页 个人信息
#import "YHYDesigneViewsViewController.h"
#import "qianViewController.h" //充值
#import "YHYMMyShowCaseViewController.h"
#import "YHYAddViewController.h"
#import "WUConnectViewController.h" //沟通过的
#import "WUStoreViewController.h"  //收藏过的
#import "WUShareSheet.h"  //分享
#import "UIView+Screen.h"
#import "UIImage+BlurScreenImage.h"

@interface WUMineViewController ()<UITableViewDataSource,UITableViewDelegate,WUMineFooterViewDelegate,WUMineHeaderViewDelegate,WUShareSheetDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) WUMineHeaderView *headView;
@property (nonatomic,strong) NSArray *titleArr;

@end

@implementation WUMineViewController

- (void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBar"] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
    //self.navigationController.navigationBarHidden = YES;
    
}

- (void)viewWillDisappear:(BOOL)animated {
    
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _titleArr=[NSArray arrayWithObjects:@"发布新任务",@"我的钱包", nil];
    
    self.view.backgroundColor = LV;
    
    //分享
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigation_share@2p"] style:UIBarButtonItemStylePlain target:self action:@selector(shareAction)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    
    //设置
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigation_shezhi@2p"] style:UIBarButtonItemStylePlain target:self action:@selector(setAction)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49) style:UITableViewStylePlain];
    self.tableView.backgroundColor = LV;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 50 * AUTO_HEIGHT;
    self.tableView.showsVerticalScrollIndicator = NO;
    //去掉线
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    // self.tableView.backgroundColor = LV;
    [self.view addSubview:_tableView];
    [self.tableView registerClass:[WUMineCell class] forCellReuseIdentifier:@"cell"];
    
    //头视图
    self.headView = [[WUMineHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 360 * AUTO_HEIGHT)];
    self.headView.delegate = self;
    self.tableView.tableHeaderView = self.headView;
    
    
    WUMineFooterView *footView = [[WUMineFooterView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 260 * AUTO_WIDTH)];
    footView.delegate = self;
    self.tableView.tableFooterView = footView;
    
    
    
}
#pragma mark -- tableView delegate && dataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 8 * AUTO_HEIGHT;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    WUMineCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.titleStr = _titleArr[indexPath.section];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    WUMineCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.selected = NO;
    
    
    if (indexPath.section == 0) {
        YHYAddViewController *designerP = [YHYAddViewController new];
        [self.navigationController pushViewController:designerP animated:YES];
    }else{
        
        qianViewController *qian=[[qianViewController alloc]init];
        [self.navigationController pushViewController:qian animated:YES];
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    [self.headView updateHeaderView:scrollView.contentOffset];
}
#pragma mark -- headerView代理方法
- (void)pushDetailViewController:(NSInteger)type {
    
    
    switch (type) {
        case MINEHEADERSELECTWORK:
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"userType"] isEqualToString:@"1"]) {
                
               
               
                
            }else {
                
                YHYMMyShowCaseViewController *tableVC = [[YHYMMyShowCaseViewController alloc] init];
                tableVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:tableVC animated:YES];
        
            }
                
            break;
            
        case MINEHEADERSELECTTALKED:
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"userType"] isEqualToString:@"1"]) {
                
                NSLog(@"我通过的我通过的");
                
            }else{
               
                WUConnectViewController *connect=[[WUConnectViewController alloc]init];
                connect.hidesBottomBarWhenPushed=YES;
                [self.navigationController pushViewController:connect animated:YES];

            }
            
            break;
        case MINEHEADERSELECTCOLLECTED:
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"userType"] isEqualToString:@"1"]) {

                NSLog(@"收藏过收藏过");
            }
            else {
               
                WUStoreViewController *store=[[WUStoreViewController alloc]init];
                store.hidesBottomBarWhenPushed=YES;
                [self.navigationController pushViewController:store animated:YES];
            }
            break;
            
        case MINEHEADERSELECTHEADER:
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"userType"] isEqualToString:@"2"]) {
               
                YHYDesigneViewsViewController *desig=[[YHYDesigneViewsViewController alloc]init];
                desig.hidesBottomBarWhenPushed=YES;
                [self.navigationController pushViewController:desig animated:YES];
                
                
            } else {
            
                 NSLog(@"我的任务我的任务我的任务我的任务");
            }
            break;
            
        case MINEHEADERSELECTSCORE:
        {
            WUVippViewController *vitality=[[WUVippViewController alloc]init];
            vitality.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vitality animated:YES];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark -- footerView代理方法
- (void)footerPushViewController:(NSInteger)type {
    
    if (type == 1200) {
        
        WUVippViewController *vitality=[[WUVippViewController alloc]init];
        vitality.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vitality animated:YES];
    } else if (type == 1201) {
        
        SupViewController *supei=[[SupViewController alloc]init];
        supei.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:supei animated:YES];
    } else {
        
        VipViewController *vipView=[[VipViewController alloc]init];
        vipView.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vipView animated:YES];
    }
}


-(void) setAction
{
    SheeViewController *chong=[[SheeViewController alloc]init];
    [self.navigationController pushViewController:chong animated:YES];
}


-(void) shareAction
{
    WUShareSheet *sheet=[[WUShareSheet alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    sheet.delegate=self;
    sheet.backImageVi.image=[[self.view convertViewToImage]applyBlurWithRadius:10.0 tintColor:[UIColor colorWithWhite:1 alpha:0.4] saturationDeltaFactor:1.8 maskImage:nil];
}

-(void) shareButtonClick:(NSInteger)index
{
    if (index ==0) {
        NSLog(@"微信微信微信");
    }else if (index ==1){
        NSLog(@"微博微博微博");
    }else if (index ==2){
        NSLog(@"朋友圈朋友圈朋友圈");
    }else{
        NSLog(@"短信短信短信");
    }
}


@end
